﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WPRotator
{
    public class PictureList
    {
        private List<string> filenameList;
        private CheckedListBox listBox;

        public List<string> FilenameList
        {
            get { return filenameList; }
        }

        public PictureList(CheckedListBox list)
        {
            filenameList = new List<string>();
            listBox = list;
        }

        public void Clear()
        {
            filenameList.Clear();
            listBox.Items.Clear();
        }

        public void Add(string file)
        {
            filenameList.Add(file);
            listBox.Items.Add(file, CheckState.Checked);
        }

        public int Count
        {
            get
            {
                return filenameList.Count;
            }
        }

        public int SelectedIndex
        {
            get
            {
                return listBox.SelectedIndex;
            }

            set
            {
                if (listBox.Items.Count > value)
                {
                    listBox.SelectedIndex = value;
                }
            }
        }

        public string SelectedFile
        {
            get
            {
                if (Count > 0 && SelectedIndex >= 0)
                {
                    return listBox.SelectedItem.ToString();
                }
                else
                {
                    return null;
                }
            }
        }

        public bool IsSelectedChecked()
        {
            return listBox.GetItemChecked(SelectedIndex);
        }

        public void RemoveSelected()
        {
            if (SelectedIndex >= 0 && Count > 0)
            {
                filenameList.RemoveAt(SelectedIndex);
                listBox.Items.RemoveAt(SelectedIndex);
            }
        }
    }
}
